package com.ruoyi.zy.controller;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.zy.domain.VmeBencao;
import com.ruoyi.zy.domain.VmeConfig;
import com.ruoyi.zy.domain.VmeJingfang;
import com.ruoyi.zy.domain.VmeYian;
import com.ruoyi.zy.service.IVmeBencaoService;
import com.ruoyi.zy.service.IVmeJingfangService;
import com.ruoyi.zy.service.IVmeYianService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Version：1.0.0
 * Created by：2024/3/30
 * Author: zhongjian
 */
@Controller
public class VmeCustomerController extends BaseController {

    @Autowired
    private IVmeBencaoService vmeBencaoService;
    @Autowired
    private IVmeJingfangService vmeJingfangService;
    @Autowired
    private IVmeYianService vmeYianService;

    // 首页
    @GetMapping("/customer/home")
    public String home() {
        return "zy/customer/home";
    }

    // 首页
    @GetMapping("/customer/index")
    public String index(ModelMap mmap) {
        VmeJingfang vmeJingfang=new VmeJingfang();
        List<VmeJingfang> listJingFang = vmeJingfangService.selectVmeJingfangList(vmeJingfang);
        mmap.put("listJingFang", listJingFang);
        return "zy/customer/index";
    }

    // 本草页
    @GetMapping("/customer/jingfanggz/{jingfangId}")
    public String bencao(@PathVariable("jingfangId") Long jingfangId,ModelMap mmap) {
        VmeJingfang vmeJingfang=vmeJingfangService.selectVmeJingfangByJingfangId(jingfangId);
        mmap.put("vmeJingfang",vmeJingfang);
        String config=vmeJingfang.getConfig();
        List<VmeConfig>  listConfig=JSON.parseArray(config,VmeConfig.class);
        mmap.put("listConfig",listConfig);
        return "zy/customer/jingfanggz";
    }

    @PostMapping("/customer/yian/list")
    @ResponseBody
    public TableDataInfo list(VmeYian vmeYian) {
        startPage();
        List<VmeYian> list = vmeYianService.selectVmeYianList(vmeYian);
        return getDataTable(list);
    }

    @GetMapping("/customer/showBenCao/{name}")
    public String showBenCao(ModelMap mmap, @PathVariable("name") String name){

        VmeBencao vmeBencao=new VmeBencao();
        vmeBencao.setName(name.split(" ")[0]);
        List<VmeBencao> list= vmeBencaoService.selectVmeBencaoList(vmeBencao);
        if(list.size()>0){
            mmap.put("bencao",list.get(0).getContent());
        }



        return "zy/customer/showbencao";
    }

}
